<template>
  <div class="main">
    <div class="back_img"></div>
    <div class="login">
      <div class="login_title">
        <h1>Login</h1>
      </div>
      <div class="login_input">
        <el-input
            prefix-icon="el-icon-user"
            placeholder="请输入账号"
            v-model="form.userNmae"
        ></el-input>
      </div>
      <div class="login_input">
        <el-input
            prefix-icon="el-icon-unlock"
            placeholder="请输入密码"
            show-password
            v-model="form.passWord"
        ></el-input>
      </div>
      <div class="login_button">
        <p @click="login">登录</p>
      </div>
    </div>
  </div>
</template>
<script>
import {login} from "../../http/api";

export default {
  data() {
    return {
      form: {
        userNmae: "",
        passWord: "",
      },
    };
  },
  created() {
    console.log(this.$route.query.redirect)
  },
  methods: {
    login() {
      login(this.form.userNmae, this.form.passWord)
          .then((res) => {
            if (res.code === 200) {
              sessionStorage.setItem("token", res.data.token);
              this.$message.success(res.data.msg);
              this.$router.push(this.$route.query.redirect);
            } else {
              this.$message.error(res.data.msg);
            }
          })
          .catch((error) => {
            this.$message.error(error);
          });
    },
  },
};
</script>

<style scoped>
.back_img {
  background: url("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01c7bc5b83cc80a80120577d640dbd.gif&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648376321&t=1d1e468e9d73dec2e0e8f89358f492a1");
  background-size: 100% 100%;
  position: fixed;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
}

.login {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  padding: 30px;
  max-width: 500px;
  min-width: 300px;
  border: 1px solid #eee;
  border-radius: 20px;
}

.login_title {
  text-align: center;
  padding-bottom: 20px;
}

.login_input:nth-child(2) {
  margin-bottom: 20px;
}

.login_input:nth-child(3) {
  margin-top: 20px;
}

.login_button {
  margin-top: 20px;
  display: flex;
}

.login_button p {
  color: #fff;
  font-size: 15px;
  display: block;
  line-height: 40px;
  text-align: center;
  cursor: pointer;
  width: 100%;
  border: 1px solid #ddd;
}

.login_button p:nth-child(1) {
  background: #409eff;
}
</style>
